home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_12_06 / saks / intq1.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1994-04-08  |  774 b   |  51 lines

  1. Listing 2 - member function definitions for a queue of int using a non-
  2. nested cell type
  3.  
  4. //
  5. // intq1.cpp - a queue of int (implementation)
  6. //
  7.  
  8. #include "intq1.h"
  9.  
  10. void intq::append(const int &e)
  11.     {
  12.     intq_cell *p = new intq_cell(e, 0);
  13.     if (first == 0)
  14.         first = p;
  15.     else
  16.         last->next = p;
  17.     last = p;
  18.     }
  19.  
  20. void intq::clear()
  21.     {
  22.     intq_cell *p;
  23.     while (first != 0)
  24.         {
  25.         p = first;
  26.         first = first->next;
  27.         delete p;
  28.         }
  29.     last = 0;
  30.     }
  31.  
  32. void intq::print(ostream &os) const
  33.     {
  34.     intq_cell *p;
  35.     for (p = first; p != 0; p = p->next)
  36.         os << ' ' << p->element;
  37.     }
  38.  
  39. int intq::remove(int &e)
  40.     {
  41.     if (first == 0)
  42.         return 0;
  43.     intq_cell *p = first;
  44.     if ((first = first->next) == 0)
  45.         last = 0;
  46.     e = p->element;
  47.     delete p;
  48.     return 1;
  49.     }
  50.  
  51.